package com.java.framework.service;

import org.springframework.data.domain.Example;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.data.jpa.domain.Specification;

import java.io.Serializable;
import java.util.List;

public interface BaseService<T, ID extends Serializable> {
    T getOne(ID id);
    T findOne(ID id);
    <S extends T> S findOne(Example<S> example);
    T findOne(Specification<T> spec);

    List<T> findAll();
    List<T> findAll(Specification<T> spec);
    List<T> findAll(Specification<T> spec, Sort sort);
    <S extends T> Page<S> findAll(Example<S> example, Pageable pageable);
    Page<T> findAll(Specification<T> spec, Sort sort, int currentPage, int pageSize);
    Page<T> findAll(Specification<T> spec, Pageable pageable);

    boolean exists(ID id);
    <S extends T> boolean exists(Example<S> example);

    <S extends T> S save(S entity);
    <S extends T> List<S> save(Iterable<S> entities);

    void delete(ID id);
    void delete(T entity);
    void deleteInBatch(Iterable<T> entities);
    void deleteAllInBatch();
}
